// N1String.h: interface for the N1String class.
//
//////////////////////////////////////////////////////////////////////

#ifndef N1STRING_H__2009_09
#define N1STRING_H__2009_09

#include "N1Object.h"
#include "N1Memory.h"

class N1Object;

class N1String : public N1Object {
public:
    typedef char      N1StringChar;
    typedef N1String  N1StringType;

protected:
    N1StringChar  *m_pStr;
    N1UInt32       m_nRealCount;


    N1StringChar* alloc(N1UInt32 count) const
    {
        return (N1StringChar*)N1Malloc( count * sizeof(N1StringChar) );
    };

    void expandBuffer(uint32 size);

public:
	N1String();

	N1String(const N1StringChar* str);

	N1String(const N1String &str);

	virtual ~N1String();

	N1NAME_DECL

	N1UInt32 length() const ;

	void setLength(N1UInt32 len);

	operator N1StringChar*() { return m_pStr; };

	const N1StringChar* str() const { return m_pStr; };

	N1StringChar* str()	{ return m_pStr; };

	N1StringChar at(N1UInt32 index) const ;

	N1StringChar& operator [](int index) { return m_pStr[index]; };

	void format(const N1StringChar* format, ...);

	void formatv(const N1StringChar* format, va_list args);

	bool operator==(const N1String& str) const ;

	bool operator==(const N1StringChar* str) const ;

    const N1String&    operator+=(N1StringChar *str);

	const N1StringType& operator+=(N1StringChar c);

	void releaseBuffer();
};

typedef N1String N1AnsiString;

#endif // N1STRING_H__2009_09
